<?php
/*
	
*/
defined('BY_JYA') or exit('Access Denied');
global $_RQ,$_AR;

$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$return=array();
$basic=$this->plugin_setting('basic');
$return['banner']=$basic['image'];
$return['basic']=$basic;
//我的关注
if($_RQ['op']=='main'){
	$id=$_RQ['id'];
	$type=$_RQ['type'];
	if(!$id){
		exi('未找到活动信息！','error');
	}
	if($type){
		$table='jy_xiuvote_looklist';
	}else{
		$table='jy_xiuvote_votelog';
	}
	$opus=pdo_get('jy_xiuvote_opus',array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));
	$reply=pdo_get('jy_xiuvote_reply',array('uniacid'=>$_SESSION['uniacid'],'id'=>$opus['rid']));
	$return['group']=pdo_get('jy_xiuvote_groups',array('uniacid'=>$_SESSION['uniacid'],'id'=>$reply['groupid']));
	$pindex = max(1, intval($_RQ['page']));
	$psize = 25;
	$list=pdo_getslice($table,array('oid'=>$opus['id'],'uniacid'=>$_SESSION['uniacid']),array($pindex,$psize),$total,$fields,'','id desc');
	$votenums=$opus['basevotenums'];
	$likes=$opus['baselikenums'];
	foreach($list as &$v){
		$v['avatar']=pdo_getcolumn('core_members',array('id'=>$v['mid']),'avatar');
		$v['nickname']=pdo_getcolumn('core_members',array('id'=>$v['mid']),'nickname');
		$jifen=pdo_getsum('jy_xiuvote_sendlplog',array('oid'=>$v['oid'],'mid'=>$v['mid'],'uniacid'=>$_SESSION['uniacid'],'status'=>1),'jifen');
		$v['nums']=1;
		$v['nums'] = $v['nums']+$jifen;
		if($type){
			$likes +=$v['nums'];
		}else{
			$votenums +=$v['nums'];
		}
	}
	$xuni=array('avatar'=>'../core/resource/images/gw-user.png','nums'=>1,'jifen'=>0);
	if($opus['baselikenums']>0 && $return['group']['type']==1){
		if($opus['baselikenums']<=$reply['everyoneuser']){
			$xuni['nums']=$opus['baselikenums'];
			$list[]=$xuni;
		}else{
			$xuni['nums']=$reply['everyoneuser'];
			$list[]=$xuni;
			$lastnums=$opus['baselikenums']-$reply['everyoneuser'];
			for ($i=1; $i<=$lastnums;){ 
				$newlastnums=$lastnums-$i;
				$max=$newlastnums>$reply['everyoneuser']?$reply['everyoneuser']:$newlastnums;
				$nums=rand(1,$max);
				$i=$i+$nums;
				$xuni['nums']=$nums;
				$list[]=$xuni;
			}
		}
	}elseif($opus['basevotenums']>0){
		if($opus['basevotenums']<=$reply['everyoneuser']){
			$xuni['nums']=$opus['basevotenums'];
			$list[]=$xuni;
		}else{
			$xuni['nums']=$reply['everyoneuser'];
			$list[]=$xuni;
			$lastnums=$opus['basevotenums']-$reply['everyoneuser'];
			for ($i=1; $i<=$lastnums; ){
				$newlastnums=$lastnums-$i;
				$max=$newlastnums>$reply['everyoneuser']?$reply['everyoneuser']:$newlastnums;
				$nums=rand(1,$max);
				$i=$i+$nums;
				$xuni['nums']=$nums;
				$list[]=$xuni;
			}
		}
	}
	paixu($list,'nums','desc');
	$return['likes']=$likes;
	$return['look']=pdo_getsum('jy_xiuvote_opus',array('id'=>$id,'status'=>1,'isshow'=>1),'look');
	$return['votenums']=$votenums;
	$return['list']=$list;
	//$return['votesum']=count($list);
	exi($return);

}